#pragma once

#include <sstream>
#include <random>
#include <string>

//! UUID生成策略
enum class UUIDGenStrategy
{
    kRandom, //!< 通用随机数生成
};

//! 根据策略生成UUID
std::string GenUUID(UUIDGenStrategy strategy = UUIDGenStrategy::kRandom)
{
    switch (strategy)
    {
        case UUIDGenStrategy::kRandom:
            {
                static thread_local std::mt19937 gen([]
                                                     {
                                                         std::random_device rd;
                                                         return std::mt19937(rd());
                                                     }());
                std::uniform_int_distribution<> dis(0, 15);
                std::uniform_int_distribution<> dis2(8, 11);

                std::ostringstream ss;
                ss << std::hex;
                for (int i = 0; i < 8; ++i)
                    ss << dis(gen);
                ss << '-';
                for (int i = 0; i < 4; ++i)
                    ss << dis(gen);
                ss << "-4";
                for (int i = 0; i < 3; ++i)
                    ss << dis(gen);
                ss << '-';
                ss << dis2(gen);
                for (int i = 0; i < 3; ++i)
                    ss << dis(gen);
                ss << '-';
                for (int i = 0; i < 12; ++i)
                    ss << dis(gen);

                return ss.str();
            }
        default:
            {
                return "";
            }
    }
}